package com.banksystem.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.banksystem.Util.TokenUtil;
import com.banksystem.entity.Member;
import com.banksystem.service.Memberservice;

@Controller
public class stcytjController {
	@Autowired
	private Memberservice ser;
	@Autowired
	private TokenUtil tokenUtil;

	/*
	 * 添加社团成员
	 */
	@RequestMapping("addcy")
	public String addcy(HttpServletRequest request ,Model model) {
		String username = tokenUtil.findUsernameBytoken(request);
		model.addAttribute("gname",username);
		return "stcytj/addcy";
	}
	@RequestMapping("addcya")
	public String addcya(String name,String sex,String classs ,String phone,String gname,String position){
		ser.addcya(name, sex, classs, phone, gname, position);
		return "stcytj/addcy";
	}
	/*
	 * 成员管理
	 */
	@RequestMapping("cygl")
	public String cygl(HttpServletRequest request,ModelMap model) {
		String gname=tokenUtil.findUsernameBytoken(request);
		List<Member> list;
		list=ser.findmemberAll(gname);
		model.addAttribute("memberlist", list);
		return "stcytj/cygl";
	}
	/*
	 * 社团成员统计
	 */
	@RequestMapping("stcyct")
	public String stcytj() {
		return "stcytj/stcytj";
	}
	
	@RequestMapping("deletemember")
	public String deletemember(String mid){
		ser.deletemember(mid);
		return "forward:cygl.do";
	}
	@RequestMapping("seachmember")
	public @ResponseBody List<Member> seachmember(String seach,HttpServletRequest request){
		String gname=tokenUtil.findUsernameBytoken(request);
		List<Member> list=ser.findMemberAlllike(seach, gname);
		return list;
	}
}
